{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Adversarial-Robustness-Toolbox for scikit-learn LogisticRegression"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from sklearn.linear_model import LogisticRegression\n",
    "\n",
    "import numpy as np\n",
    "from matplotlib import pyplot as plt\n",
    "\n",
    "from art.estimators.classification import SklearnClassifier\n",
    "from art.attacks.evasion import ProjectedGradientDescent\n",
    "from art.utils import load_mnist\n",
    "\n",
    "import warnings\n",
    "warnings.simplefilter('ignore')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Load and transform MNIST dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "(x_train, y_train), (x_test, y_test), min_, max_ = load_mnist()\n",
    "\n",
    "n_samples_train = x_train.shape[0]\n",
    "n_features_train = x_train.shape[1] * x_train.shape[2] * x_train.shape[3]\n",
    "n_samples_test = x_test.shape[0]\n",
    "n_features_test = x_test.shape[1] * x_test.shape[2] * x_test.shape[3]\n",
    "\n",
    "x_train = x_train.reshape(n_samples_train, n_features_train)\n",
    "x_test = x_test.reshape(n_samples_test, n_features_test)\n",
    "\n",
    "y_train = np.argmax(y_train, axis=1)\n",
    "y_test = np.argmax(y_test, axis=1)\n",
    "\n",
    "n_samples_max = 100\n",
    "x_train = x_train[0:n_samples_max]\n",
    "y_train = y_train[0:n_samples_max]\n",
    "x_test = x_test[0:n_samples_max]\n",
    "y_test = y_test[0:n_samples_max]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Train LogisticRegression classifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = LogisticRegression(penalty='l2', dual=False, tol=0.0001, C=1.0, fit_intercept=True, intercept_scaling=1, \n",
    "                           class_weight='balanced', random_state=None, solver='lbfgs', max_iter=100, \n",
    "                           multi_class='ovr', verbose=0, warm_start=False, n_jobs=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LogisticRegression(C=1.0, class_weight='balanced', dual=False,\n",
       "                   fit_intercept=True, intercept_scaling=1, l1_ratio=None,\n",
       "                   max_iter=100, multi_class='ovr', n_jobs=None, penalty='l2',\n",
       "                   random_state=None, solver='lbfgs', tol=0.0001, verbose=0,\n",
       "                   warm_start=False)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.fit(X=x_train, y=y_train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Create and apply ProjectedGradientDescent Attack with ART"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "art_classifier = SklearnClassifier(model=model)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "pgd = ProjectedGradientDescent(estimator=art_classifier, norm=np.inf, eps=.3, eps_step=0.1, max_iter=20, \n",
    "                               targeted=False, num_random_init=0, batch_size=128)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "x_train_adv = pgd.generate(x_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_test_adv = pgd.generate(x_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Evaluate LogisticRegression classifier on benign and adversarial samples"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Benign Training Score: 1.0000\n"
     ]
    }
   ],
   "source": [
    "score = model.score(x_train, y_train)\n",
    "print(\"Benign Training Score: %.4f\" % score)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAECCAYAAAD+eGJTAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAO90lEQVR4nO3dbYxc5XnG8euKvdg1mMRbx45DHXCMU2igMemKFxkBFQp1o0qAKkKtKHJoWtMEJ6F1JahVFVqRyq2AlFKKZIqLkYAEAhR/oEksCwFRYYvtEjBxgARcarxdY1ZgIMTYu3c/7Ljdkt1ndndeznjv/09azcy5Z+bcPravfc6cZ85xRAhAXh+ougEA1SIEgOQIASA5QgBIjhAAkiMEgOQqCQHby20/b/sntq+uoocS27tsP2v7adtbO6CfDbb32t4xYlm37c22X6zdzumw/q61/WptGz5t+7MV9rfQ9iO2d9p+zvbXa8s7YhsW+mvLNnS75wnYnibpBUmfkbRb0lOSVkTEj9raSIHtXZJ6ImJf1b1Iku1zJL0t6c6IOKW27G8lDUTEulqQzomIqzqov2slvR0R11fR00i2F0haEBHbbc+WtE3SRZK+qA7YhoX+Pqc2bMMqRgKnS/pJRLwUEe9J+pakCyvo44gREY9JGnjf4gslbazd36jhfzSVGKO/jhERfRGxvXb/LUk7JR2nDtmGhf7aoooQOE7Sf414vFtt/AOPU0j6vu1ttldV3cwY5kdEnzT8j0jSvIr7Gc1q28/Udhcq210ZyfYJkk6T1KsO3Ibv609qwzasIgQ8yrJOm7u8LCI+Lem3JV1RG+5iYm6VtFjSUkl9km6oth3J9jGS7pd0ZUTsr7qf9xulv7ZswypCYLekhSMe/4qkPRX0MaaI2FO73SvpQQ3vwnSa/tq+5OF9yr0V9/P/RER/RAxGxJCk21TxNrTdpeH/YHdFxAO1xR2zDUfrr13bsIoQeErSEtuLbB8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1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.matshow(x_train[0, :].reshape((28, 28)))\n",
    "plt.clim(0, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Benign Training Predicted Label: 5\n"
     ]
    }
   ],
   "source": [
    "prediction = model.predict(x_train[0:1, :])[0]\n",
    "print(\"Benign Training Predicted Label: %i\" % prediction)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Adversarial Training Score: 0.2400\n"
     ]
    }
   ],
   "source": [
    "score = model.score(x_train_adv, y_train)\n",
    "print(\"Adversarial Training Score: %.4f\" % score)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAECCAYAAAD+eGJTAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAQqElEQVR4nO3dfZBV9X3H8c83skIEVB6EUnzEkIkmnaBZHyKdjJWpJTbxYVoy5Q9LZ5yuk8aONmmrYzqjnTEt6URT/4kdjEywNXZ01Eqn1IeiU2RMiIulgmJBkRBk3VUR8RF34ds/9pJuye7vt3vPPfec9ft+zTC7e7737vlydvlw7v39zu+YuwtAXJ+ougEA1SIEgOAIASA4QgAIjhAAgiMEgOAqCQEzW2xm/2NmL5nZDVX0kGJmO81ss5ltMrPuGvSz0sz6zGzLkG3TzexxM9ve+DitZv3dbGavNo7hJjO7pML+TjKzJ81sq5k9b2bXNrbX4hgm+mvLMbR2zxMws6MkbZP025J2S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1uyvmb242Puaah+P5isf+rY15P1+586L1mftiX9f8rxL6Wvt69abj2AovMAuO8AgFoiBIDgCAEgOEIACI4QAIIjBIDgCAEgOOYJDPHadRck6+92fpCs//5nqx0H3j3wbrJ+zSu/l6zvundesn7atmrH+XPj9Llx/sLj9Jn7BoxXnAkAwRECQHCEABAcIQAERwgAwRECQHCEABBcqHkCB373nGR95ld2p+sF9/9vr3w2Wf/MCb3J+rz1V6eff8sryfqbF6fnAaTvCpAfp8+Nw+fuC5BT1+vxxzvOBIDgCAEgOEIACI4QAIIjBIDgCAEgOEIACM7cPf0As5Mk3S3p1yQdkrTC3W83s5sl/bGkw4vV3+jua1Lf61ib7ufZ+L2bedFx7rJNeGJjsr6v5Ovhc9fz5+T6R/M2+Frt9702XG00k4UGJH3L3Z81s6mSNprZ4btgfN/dv9eqRgG0XzYE3L1HUk/j83fMbKukuWU3BqA9xvSegJmdKuksSRsam64xs+fMbKWZTWtxbwDaYNQhYGZTJD0g6Tp33y/pDkmnS1qgwTOFW0d4XpeZdZtZd78OtKBlAK00qhAwsw4NBsA97v6gJLl7r7sfdPdDku6UdO5wz3X3Fe7e6e6dHZrYqr4BtEg2BMzMJN0laau73zZk+5whD7tC0pbWtwegbKMZHVgo6UpJm81sU2PbjZKWmtkCSS5pp6T0da4Aamk0owPrJQ03vpicEzAejfd5AFUrel8AVIMZg0BwhAAQHCEABEcIAMERAkBwhAAQHCEABBfqvgM5uXHuspW9rj7r9mM4nAkAwRECQHCEABAcIQAERwgAwRECQHCEABBc9r4DLd2Z2euSfj5k00xJb7StgbGjv2Lq3F+de5Na398p7n7CcIW2hsCv7Nys2907K2sgg/6KqXN/de5Nam9/vBwAgiMEgOCqDoEVFe8/h/6KqXN/de5NamN/lb4nAKB6VZ8JAKgYIQAERwgAwRECQHCEABDc/wI2UNnGRLE8DQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 288x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.matshow(x_train_adv[0, :].reshape((28, 28)))\n",
    "plt.clim(0, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Adversarial Training Predicted Label: 7\n"
     ]
    }
   ],
   "source": [
    "prediction = model.predict(x_train_adv[0:1, :])[0]\n",
    "print(\"Adversarial Training Predicted Label: %i\" % prediction)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Benign Test Score: 0.7000\n"
     ]
    }
   ],
   "source": [
    "score = model.score(x_test, y_test)\n",
    "print(\"Benign Test Score: %.4f\" % score)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAECCAYAAAD+eGJTAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAODklEQVR4nO3df4xc5XXG8eeJvazjtWnsOHZcY3BDSBSSBlNtIJHbyhElJYmQQQltLNVypTSLWpCgitoiSxGW2qYU8aO0aZFMceNEhoTGUFDiprGstBSVOtiWAYNpTalLHW+9gNPaBPDP0z/2mm7J7ju7Oz/urM/3I61m5p479x5fzz773pl37zoiBCCvt9XdAIB6EQJAcoQAkBwhACRHCADJEQJAcrWEgO0rbP+L7edt31RHDyW299l+2vYu29u7oJ/1tods7x6xbK7tLbb3Vrdzuqy/tbZ/WB3DXbY/VWN/i21/3/Ye28/YvqFa3hXHsNBfR46hOz1PwPY0Sf8q6XJJ+yU9IWllRDzb0UYKbO+T1B8RL9fdiyTZ/kVJr0r6WkR8qFp2q6R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cIAMnVHQLrat5/I/TXnG7ur5t7kzrYX63vCQCoX90jAQA1IwSA5AgBIDlCAEiOEACS+1/8tsxjstIf5QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 288x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.matshow(x_test[0, :].reshape((28, 28)))\n",
    "plt.clim(0, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Benign Test Predicted Label: 7\n"
     ]
    }
   ],
   "source": [
    "prediction = model.predict(x_test[0:1, :])[0]\n",
    "print(\"Benign Test Predicted Label: %i\" % prediction)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Adversarial Test Score: 0.1000\n"
     ]
    }
   ],
   "source": [
    "score = model.score(x_test_adv, y_test)\n",
    "print(\"Adversarial Test Score: %.4f\" % score)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAECCAYAAAD+eGJTAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAPy0lEQVR4nO3df6xX9X3H8dcbuUDlh0AQREoLUlxplxXdjXSjabREw0wWtZlb+cPRrOn1j5rWrNlqSBb5Z4nbqq5ZNhccrLRaNxNU7GY2GetCTTsmUCIw6kSHFr29F3vbgZUhP9774x7cLd77OZf7+Z4fl/fzkZD7/Z739/s9b8+Fl+d8z+d8jrm7AMQ1oekGADSLEACCIwSA4AgBIDhCAAiOEACCayQEzGy1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RECQHCEABAcIQAERwgAwRECQHCME+igqq9X7195Jln/g9kvZ62/zII/SV8Pf/qGa9P1zPsq5N6XoOr5HMYr9gSA4AgBIDhCAAiOEACCIwSA4AgBIDhCAAiudJyAmS2U9A1JV0g6K2mDu3/NzNZL+ryko8VL17n7M1U12gZVn2cue/+Vf3hV1uffePA3k/VDh+cl61f7rmQ997+/7L4BTWvrfQNyjWaw0GlJX3b3PWY2XdJuM9tW1B50969W1x6AqpWGgLv3SuotHh83s4OSFlTdGIB6XNB3Ama2SNI1knYWi+4ysxfMbJOZzepwbwBqMOoQMLNpkrZIutvdj0l6SNISScs1uKdw/wjv6zGzXWa265Ty5qAD0HmjCgEz69JgADzq7k9Ikrv3ufsZdz8r6WFJ1w33Xnff4O7d7t7dpcmd6htAh5SGgJmZpI2SDrr7A0OWzx/ystsk7e98ewCqNpqzAysl3SFpn5ntLZatk7TGzJZLckmHJd1ZSYcAKjWaswPPSRpuwvmLbkxA7vXubffygSuT9au/uDNZb7uo8wHkYsQgEBwhAARHCADBEQJAcIQAEBwhAARHCADBmbvXtrIZNttX2Kra1gdg0E7frmM+MNx4H/YEgOgIASA4QgAIjhAAgiMEgOAIASA4QgAIrtZxAmZ2VNKrQxbNkfRmbQ1cOPrL0+b+2tyb1Pn+Pujulw9XqDUE3rNys13u3t1YAyXoL0+b+2tzb1K9/XE4AARHCADBNR0CGxpefxn6y9Pm/trcm1Rjf41+JwCgeU3vCQBoGCEABEcIAMERAkBwhAAQ3P8Biyeq37yblYMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 288x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.matshow(x_test_adv[0, :].reshape((28, 28)))\n",
    "plt.clim(0, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Adversarial Test Predicted Label: 9\n"
     ]
    }
   ],
   "source": [
    "prediction = model.predict(x_test_adv[0:1, :])[0]\n",
    "print(\"Adversarial Test Predicted Label: %i\" % prediction)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Investigate dependence on attack budget eps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEKCAYAAAAfGVI8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nO3de3QU9f3/8ec7mxsQwh1BLiIVFRAViCBCtVZ/rVewCBYoVrwU8YK17a/92q/6q7U9tdraWhBFFLXeCl4q4l1bxXKXoCiCogEsIlSi3EESAu/fH7vUNeSygUxmk3k9ztmT3dmZ3ZcjyWtnZucz5u6IiEh0ZYQdQEREwqUiEBGJOBWBiEjEqQhERCJORSAiEnEqAhGRiAusCMzsfjPbYGbvVfK8mdkEMysys3fNrE9QWUREpHJBbhE8CJxRxfNnAt0St7HA3QFmERGRSgRWBO7+L2BjFbMMAR7yuAVAczNrH1QeERGpWGaI790B+CTp8drEtPXlZzSzscS3GmjSpEnfo48+uk4Ciog0FIsXL/7c3dtU9FyYRWAVTKtwvAt3nwJMASgoKPDCwsIgc4mINDhm9u/KngvzW0NrgU5JjzsC60LKIiISWWEWwUzgh4lvD50IbHH3/XYLiYhIsALbNWRmfwO+BbQ2s7XAr4AsAHefDLwAnAUUATuBi4PKIiIilQusCNx9ZDXPO3BVUO8vIiKp0ZnFIiIRpyIQEYk4FYGISMSpCEREIk5FICIScSoCEZGIUxGIiEScikBEJOJUBCIiEaciEBGJOBWBiEjEqQhERCJORSAiEnEqAhGRiFMRiIhEnIpARCTiVAQiIhGnIhARiTgVgYhIxKkI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AriT/0u4GriI8c29PMFgNbiB9HiAGPmFkz4lsSf3b3zSFFF6mSRh8VOUhmtt3d9Wlf6i3tGhIRiThtEYiIRJy2CEREIk5FICIScSoCEZGIUxGIiEScikBEJOL+P2Gi0wttRzusAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "eps_list = [0.1, 0.2, 0.3, 0.4, 0.5]\n",
    "score_list = list()\n",
    "\n",
    "for eps in eps_list:\n",
    "    pgd = ProjectedGradientDescent(estimator=art_classifier, norm=np.inf, eps=eps, eps_step=0.05, max_iter=20, \n",
    "                                   targeted=False, num_random_init=0, batch_size=128)\n",
    "    x_test_adv = pgd.generate(x_test)\n",
    "    score = model.score(x_test_adv, y_test)\n",
    "    score_list.append(score)\n",
    "\n",
    "plt.plot(eps_list, score_list)\n",
    "plt.xlabel('eps')\n",
    "plt.ylabel('Test Accuracy')\n",
    "plt.ylim((0, 1));"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Targeted PGD attack"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "pgd = ProjectedGradientDescent(estimator=art_classifier, norm=np.inf, eps=0.5, eps_step=0.01, max_iter=50, \n",
    "                               targeted=True, num_random_init=3, batch_size=128)\n",
    "y_test_target = np.zeros((y_test.shape[0], 10))\n",
    "target_label = 7\n",
    "y_test_target[:, target_label] = 1\n",
    "x_test_adv = pgd.generate(x_test, y=y_test_target)\n",
    "score = model.score(x_test_adv, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Targeted Adversarial Test Score: 0.2100\n"
     ]
    }
   ],
   "source": [
    "score = model.score(x_test_adv, np.argmax(y_test_target, axis=1))\n",
    "print(\"Targeted Adversarial Test Score: %.4f\" % score)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAECCAYAAAD+eGJTAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAV6ElEQVR4nO3df3RU5ZkH8O+TyS8SQgg/EgIEUIIgZ1ejG8GqdXXZra52q56WKrYeeo5t8JzaVexu67p7qu6edd1WUXfb6uKPI66Ch1210kpVim1RUQSEFRSQXwFCYhCCEAJJmMmzf2Sw0eY+b8idmTvh/X7O4SSZb+bOk5vJw5153/teUVUQkb9yoi6AiKLFJkDkOTYBIs+xCRB5jk2AyHNsAkSei6QJiMjlIrJFRLaJyO1R1GARkXoR2SAi60VkTRbU84SI7BORjT1uGyYiy0Rka/JjWZbVd5eI7E3uw/UickWE9VWJyG9FZJOIvC8ityRvz4p9aNSXkX0omZ4nICIxAB8C+CsADQBWA5ilqh9ktBCDiNQDqFXV/VHXAgAicjGAIwCeUtU/Sd72YwAtqnpvspGWqeoPs6i+uwAcUdX7oqipJxGpBFCpqu+KSAmAtQCuBvAtZME+NOr7OjKwD6M4EpgGYJuq7lDVTgDPArgqgjoGDFVdAaDlczdfBWBB8vMF6H7SRCKgvqyhqk2q+m7y81YAmwCMQZbsQ6O+jIiiCYwBsKfH1w3I4A/cRwrgVRFZKyJ1URcToEJVm4DuJxGA8ojr6c3NIvJe8uVCZC9XehKRCQDOAbAKWbgPP1cfkIF9GEUTkF5uy7a5yxeq6rkA/hrAd5OHu3RyHgYwEUANgCYA90dbDiAigwE8B+BWVT0cdT2f10t9GdmHUTSBBgBVPb4eC6AxgjoCqWpj8uM+AC+g+yVMtmlOvpY88ZpyX8T1fIaqNqtqQlW7ADyKiPehiOSh+w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Is+xCRB5jk2AyHNsAkSeYxMg8hybAJHnRB1j0yl9MJGPAezqcdMIAPszVsDJY33hZHN92VwbkPr6xqvqyN6CjDaBP3pwkTWqas+AiRDrCyeb68vm2oDM1seXA0SeYxMg8lzUTWB+xI/vwvrCyeb6srk2IIP1RfqeABFFL+ojASKKGJsAkefYBIg8xyZA5Dk2ASLP/T+6oyk91j0sBwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 288x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.matshow(x_test_adv[16, :].reshape((28, 28)))\n",
    "plt.clim(0, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Target Label: 7\n",
      "Predicted Label: 7\n"
     ]
    }
   ],
   "source": [
    "prediction = model.predict(x_test_adv[16:17, :])[0]\n",
    "print(\"Target Label: %i\" % target_label)\n",
    "print(\"Predicted Label: %i\" % prediction)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
